package elkaiyohrempfeil;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;

import javax.swing.JComponent;

import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.opengis.feature.simple.SimpleFeature;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.LineString;

public class MyMap extends JComponent
{
	AffineTransform world2pixel;
	ArrayList<LineString> aLLineString;
	Point2D p1,p2;
	Coordinate coord1,coord2;
	public MyMap(AffineTransform world2pixel, ArrayList<LineString> aLLineString) 
	{
		this.world2pixel = world2pixel;
		this.aLLineString = aLLineString;
	}

	public void paintComponent(Graphics g) 
	{
		Graphics2D g2D = (Graphics2D) g;
		for (int i = 0; i < aLLineString.size()-1; i++) 
		{
			for (int j = 0; j < aLLineString.get(i).getNumPoints()-1; j++) 
			{
				coord1 = aLLineString.get(i).getCoordinateN(j);
				coord2 = aLLineString.get(i).getCoordinateN(j+1);
				p1 = new Point2D.Double(coord1.y, coord1.x);
				p2 = new Point2D.Double(coord2.y, coord2.x);
				System.out.println("Before: "+p1.toString());
				System.out.println("After: "+world2pixel.transform(p1, null));
				System.out.println("Before: "+p2.toString());
				System.out.println("After: "+world2pixel.transform(p2, null));
				p1 = world2pixel.transform(p1, null);
				p2 = world2pixel.transform(p2, null);
//				System.out.println(p1.toString()+","+p2.toString());
//				Point point = geometryFactory.createPoint( new Coordinate(p.getY(),p.getX()));
//				SimpleFeature feature = SimpleFeatureBuilder.build( TYPE, new Object[]{point, ""}, null );
//	            collection.add( feature );
				g2D.draw(new Line2D.Double(p1, p2));
			}	
		}
	  	
//	  	Point2D p1 = new Point2D.Double(10.0, 10.0);
//	  	Point2D p2 = new Point2D.Double(20.0, 20.0);
//	  	Point2D p3 = new Point2D.Double(5.0, 45.0);
//	  	g2D.draw(new Line2D.Double(p1, p2));
//	  	g2D.draw(new Line2D.Double(p2, p3));
	}
}
